// pages/admin/admin.js
Page({
  data: {
    todayStats: {
      newUsers: 0,
      newOrders: 0,
      completedOrders: 0,
      revenue: 0
    },
    pendingComplaints: 0,
    recentActivities: []
  },

  onLoad() {
    this.loadAdminData()
  },

  onShow() {
    this.loadAdminData()
  },

  loadAdminData() {
    // 模拟加载管理员数据
    setTimeout(() => {
      this.setData({
        todayStats: {
          newUsers: 23,
          newOrders: 156,
          completedOrders: 142,
          revenue: 2580
        },
        pendingComplaints: 2,
        recentActivities: [
          {
            id: 1,
            icon: '👤',
            title: '新用户注册：张同学',
            time: '5分钟前'
          },
          {
            id: 2,
            icon: '📋',
            title: '订单完成：代课服务 #12345',
            time: '10分钟前'
          },
          {
            id: 3,
            icon: '⚠️',
            title: '用户投诉：快递代拿纠纷',
            time: '15分钟前'
          },
          {
            id: 4,
            icon: '✅',
            title: '订单完成：代拿快递',
            time: '20分钟前'
          }
        ]
      })
    }, 800)
  },

  navigateToUserManagement() {
    wx.navigateTo({
      url: '/pages/admin/user-management/user-management'
    })
  },


  navigateToOrderManagement() {
    wx.navigateTo({
      url: '/pages/admin/order-management/order-management'
    })
  },

  navigateToComplaintManagement() {
    wx.navigateTo({
      url: '/pages/admin/complaint-management/complaint-management'
    })
  },

  navigateToSystemSettings() {
    wx.navigateTo({
      url: '/pages/admin/system-settings/system-settings'
    })
  },

  navigateToNoticeManagement() {
    wx.navigateTo({
      url: '/pages/admin/notice-management/notice-management'
    })
  },

  navigateToDataAnalysis() {
    wx.navigateTo({
      url: '/pages/admin/data-analysis/data-analysis'
    })
  },

  navigateToFinancialReport() {
    wx.navigateTo({
      url: '/pages/admin/financial-report/financial-report'
    })
  },

  sendSystemNotice() {
    wx.showModal({
      title: '发送系统通知',
      content: '请输入通知内容',
      editable: true,
      placeholderText: '请输入通知内容',
      success: (res) => {
        if (res.confirm && res.content) {
          wx.showLoading({ title: '发送中...' })
          
          // 模拟发送通知
          setTimeout(() => {
            wx.hideLoading()
            wx.showToast({
              title: '通知发送成功',
              icon: 'success'
            })
          }, 1500)
        }
      }
    })
  },

  exportData() {
    wx.showActionSheet({
      itemList: ['导出用户数据', '导出订单数据', '导出财务数据'],
      success: (res) => {
        const dataTypes = ['用户数据', '订单数据', '财务数据']
        const selectedType = dataTypes[res.tapIndex]
        
        wx.showLoading({ title: '导出中...' })
        
        // 模拟导出数据
        setTimeout(() => {
          wx.hideLoading()
          wx.showToast({
            title: `${selectedType}导出成功`,
            icon: 'success'
          })
        }, 2000)
      }
    })
  },

  systemMaintenance() {
    wx.showModal({
      title: '系统维护',
      content: '确定要进入系统维护模式吗？维护期间用户将无法正常使用。',
      success: (res) => {
        if (res.confirm) {
          wx.showLoading({ title: '设置中...' })
          
          // 模拟系统维护设置
          setTimeout(() => {
            wx.hideLoading()
            wx.showToast({
              title: '已进入维护模式',
              icon: 'success'
            })
          }, 1500)
        }
      }
    })
  }
})